﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SimpleRssReader.ViewModel;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows8Accelerator.Core.Xaml;
using Windows8Accelerator.Core.Xaml.Helpers;

namespace SimpleRssReader
{
    public sealed partial class HomePage : Page
    {
        public HomePage()
        {
            this.InitializeComponent();
            SuperSemanticZoomListView.PageDestinationTypeOnItemClick = typeof(PostPage);
            SuperSemanticZoomListView.PageDestinationTypeOnGroupHeaderClick = typeof(BlogPage);
            SuperSemanticZoomListView.ItemColumnAndRowSpanSelector = HomeViewModel.ItemColumnAndRowSpanSelector;
        }

        public HomeViewModel ViewModel
        {
            get { return DataContext as HomeViewModel; }
        }

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (ViewModel == null)
            {
                DataContext = AppHelperBase.Instance.GetOrCreatePageViewModel<HomeViewModel>(this);
            }
            await ViewModel.LoadAsync();            
        }
}
}
